#include<iostream>
#include<stdio.h>

#include <iomanip>
#include  <cmath>
#include <stdlib.h>
#include <cstring>
#include <malloc.h>
#include<stdio.h>
#include<cassert>
#include <stdio.h>
using namespace std;
int main() {
    int i = 0, j = 0, k = 0;
    int n = 0;
    int d = 0;
    int g = 0;
    int h = 0;
    int t = 0, b = 0, x = 0;
    cin >> n;
    int arr[3][1000];
    int sum[3][1000];
    for (i = 0; i < n; i++) {
        cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
        sum[1][i] = arr[0][i] + arr[1][i] + arr[2][i];
    }
    for (i = 0; i < n; i++)
        for (j = i + 1; j < n; j++) {
            if (abs(arr[0][i] - arr[0][j]) <= 5 && abs(arr[1][i] - arr[1][j]) <= 5 &&
                abs(arr[2][i] - arr[2][j]) <= 5 && abs(sum[1][i] - sum[1][j]) <= 10)
            {
                k++;
            }
        }
    cout << k;
}